/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Action;

import Map.MapLevel;
import Map.Map;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 *
 * @author insane
 */
public class Events {

    private static Events instance = new Events();

    private Events() {
    }

    public static Events getInstance() {
        return instance;
    }

    public void checkEvents(Map map) throws FileNotFoundException, IOException, ClassNotFoundException {
        if (map.getMap()[map.x][map.y] != '.') {
            EventsList(map.getMap()[map.x][map.y]);
        }
    }

    private void EventsList(char i) throws FileNotFoundException, IOException, ClassNotFoundException {
        switch (i) {
            case '<'://uplevel
                Up();
                break;
            case '>'://downlevel
                Down();
                break;
        }
    }

    private void Up() throws FileNotFoundException, IOException, ClassNotFoundException{
        MapLevel.getInstance().setLevel(MapLevel.getInstance().getLevel() - 1);
        Map map = MapLevel.getInstance().getMap();
        for(int h = 0;h < map.getHeight(); h++)
            for(int w = 0; w < map.getWidth(); w++)
                if(map.getMap()[w][h]=='>'){
                map.x = w;
                map.y = h;
                return;
                }
    }

    private void Down() throws FileNotFoundException, IOException, ClassNotFoundException {
        MapLevel.getInstance().setLevel(MapLevel.getInstance().getLevel() + 1);
        Map map = MapLevel.getInstance().getMap();
        for(int h = 0;h < map.getHeight(); h++)
            for(int w = 0; w < map.getWidth(); w++)
                if(map.getMap()[w][h]=='<'){
                map.x = w;
                map.y = h;
                return;
                }
    }
}
